<!DOCTYPE HTML>
<html>
<head>
    <title>商城弹出LOGO</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <script src="/scripts/boot.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <link rel="stylesheet" href="/editor/common.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body  style="padding: 0;width: 100%;height: 97%">
<div style="width:99%;height: 97%;">
    <div id="outImg">
        <img id="imgId" src="" alt="" onclick="smallImg()">
    </div>
    <div style="width:99%;">
        <div style="padding: 5px">
            <span>商品所属商城：</span><input  class="mini-combobox" type="text" id="goodsInShopType" data="shopGoodsTypeData"/>
            <a class="mini-button" iconCls="icon-search" onclick="search()">查找</a>
        </div>
        <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
                        <!--<a class="mini-button" iconCls="icon-edit" onclick="edit()">编辑</a>-->
                        <a class="mini-button" iconCls="icon-remove" onclick="remove()">刪除</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div id="datagrid1" class="mini-datagrid" style="width:99%;height: 97%;" multiSelect="true"
         url="/getdata/getShopPopUpLogo" idField="id" allowResize="true"
         sizeList="[20,30,50,100]" pageSize="20">
        <div property="columns">
            <div type="checkcolumn" width="20" ></div>
            <div field="objectId" width="80" headerAlign="center" allowSort="true" >ObjectID</div>
            <div field="logo"  width="70" headerAlign="center" align="center" headerAlign="center"  allowSort="true" >LOGO</div>
            <div field="goodsShopOId" width="80" headerAlign="center" allowSort="true" >所属商城商品Id</div>
            <div field="shopIcon"  width="70" headerAlign="center" align="center" headerAlign="center"  allowSort="true" >商品Icon</div>
            <div field="title" width="80" headerAlign="center" align="center" allowSort="true" >商品名称</div>
            <div field="goodsShopType" width="80" renderer="statusRenderer" headerAlign="center" align="center" allowSort="true" >商品所属商城</div>
            <div field="goodsUrl" width="80" headerAlign="center" align="center" allowSort="true" >点击跳转URL</div>
            <div field="updatedAt" Swidth="100" renderer="onBirthdayRenderer"   align="center" headerAlign="center" allowSort="true">更新日期</div>
            <div field="createdAt" Swidth="100" renderer="onBirthdayRenderer"   align="center" headerAlign="center" allowSort="true">创建日期</div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
  let shopGoodsTypeData = [{id:-1,text:''},{id:0,text:'普通商城'},{id:1,text:'积分商城'}]
  var flag = 1;
  mini.parse();
  var grid = mini.get("datagrid1");
  grid.load();
  grid.on("drawcell", function (e) {
    var value = e.value;
    var column = e.column;
    if (column.field == "shopIcon") {
      if(value) {
        e.cellHtml = '<img class="bigImg" onclick="bigImg()" src="' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto-orient" width="30" height="30" alt="图片">';
      }else{
        e.cellHtml = '<img class="bigImg" onclick="bigImg()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
      }
    } else if (column.field == "logo"){
      if(value) {
        e.cellHtml = '<img class="bigImg" onclick="logoBigImg()" src="' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto-orient" width="30" height="30" alt="图片">';
      }else{
        e.cellHtml = '<img class="bigImg" onclick="logoBigImg()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
      }
    }
  });
  function statusRenderer(e) {
    var value = e.value;
    if (value=="0") {
      return (value, '普通商城')
    }else if(value== "1"){
      return (value, '积分商城')
    }
  };
  function bigImg() {
    var row = grid.getSelected();
    if (row) {
      if(flag==1) {
        var path = row.shopIcon;
        $("#imgId").attr('src', path);
        $("#outImg").css('display','block');
      }
    }
  }
  function logoBigImg() {
    var row = grid.getSelected();
    if (row) {
      if(flag==1) {
        var path = row.logo;
        $("#imgId").attr('src', path);
        $("#outImg").css('display','block');
      }
    }
  }
  function smallImg() {
    $("#outImg").css('display','none');
  }

  function onBirthdayRenderer(e) {
    var value = e.value;
    if (value) return mini.formatDate(value, 'yyyy-MM-dd hh:mm:ss');
    return "";
  }

  function onSelectedChanged(e) {
    var row = e.sender;
    var record = row.getSelected();
    if (record) {
       objectId = record.id;
    }
  };

  function  add() {
    mini.open({
      url: "/getdata/shopPopUpLogoMangerAdd",
      title: "添加商城弹出Logo", width: 560, height: 500,
      ondestroy: function (action) {
        grid.reload();
      }
    });
  }

  function  remove() {
    var row = grid.getSelected()
    if(row){
      $.ajax({
        url:'/getdata/delShopPopUpLogo',
        type:'POST',
        data:{
          objectId:row.objectId
        },
        success:function (result) {
          if(result){
            grid.reload();
          }else{
            alert("删除失败");
          }
        }
      })
    }else {
      alert("请选中一条记录");
    }
  }
  function search() {
    let goodsInShopType = mini.get("goodsInShopType").getValue();
    if (!goodsInShopType){
      goodsInShopType = ''
    }
    grid.load({
      goodsInShopType:goodsInShopType
    });
  }

</script>
</html>
